<template>
	<view class="tableContent">
		<view class="nav" v-if="tableType != 3">
			<view class="navItem" v-for="(item,index) in navList" :key="index" @click="navClick(item.type)">{{item.name}}<i class="iconfont iconxiala"></i></view>
		</view>
		<view class="none" v-if="tableType != 3 && courseList.length == 0">
			<i class="iconfont iconzanwukecheng"></i>
			<text>当前暂无课表</text>
		</view>
		<view class="table" v-if="courseList.length > 0 || tableType == 3">
			<view class="table-tr">
				<view class="table-td">
					<view class="date">日期</view>
					<view class="time">时段</view>
				</view>
				<view class="table-td" v-for="(item,index) in days" :key="index" v-if="tableType == 3">
					<view class="day-name">{{item.name}}</view>
				</view>
				<view class="table-td" v-for="(item,index) in daysNew" :key="index"  v-if="tableType != 3">
					<view class="day-name">{{item.name}}</view>
					<view class="day-time">{{ item.time }}</view>
				</view>
			</view>
			<view class="table-tr" v-for="(item,index) in timeList" :key="index">
				<view class="table-td course-time">
					<view>{{item.start}}</view><view>-</view><view>{{item.end}}</view>
				</view>
				<view class="table-td course-text" v-for="(item1,index1) in datas[item.unid]" :key="index1" @click="showClass(item1,index1,item.unid)"
				:class="item1.timeType == 2 ? 'time-less' : item1.timeType == 3 ? 'time-ing': item1.timeType == 1 ? 'time-more':''">
					<view>{{item1.subject_name ? item1.subject_name : '-'}}</view>
					<view v-if="item1.subject_name && tableType == 1 && item1.timeType != 1" class="sign" :class="(item1.timeType == 2 && item1.sign_type == 1) || (item1.timeType == 3 && item1.sign_type == 1) ? 'signSuccess': item1.timeType == 2 && item1.sign_type == 2 ? 'signLate':item1.timeType == 3 && item1.sign_type == 2 ?'signIngLate':item1.timeType == 2 ? 'signDefault':''"></view>
				</view>
			</view>
		</view>
		<!-- 弹框 -->
		<view class="pop" v-if="isShowPop" @tap="closeALL">
			<scroll-view scroll-y="true" :class="showArr.length >= 10 ? 'popView' : 'popShort'">
				<view>
					<view class="popItem" :class="item.isShow ? 'popActive' : ''" v-for="(item, index) in showArr" :key="index" @tap.stop="itemClick(index,item.name)">{{item.name}}</view>
				</view>
			</scroll-view>
		</view>
		<!-- 课程详情 -->
		<view class="pop" v-if="isClass" @tap="closeALL">
			<view class="popShort">
				<view class="popTitle">{{classCont.subject_name}}</view>
				<view class="popCont">
					<view class="popCont_item"><text>时间：</text>{{classCont.time.timeStart}}-{{classCont.time.timeEnd}}</view>
					<!-- <view class="popCont_item" v-if="tableType == 1"><text>老师：</text>{{classCont.teacher_name}}</view> -->
					<view class="popCont_item" v-if="tableType == 1"><text>教室：</text>{{classCont.className}}</view>
					<!-- <view class="popCont_item" v-if="tableType == 1"><text>状态：</text></view> -->
					<view class="popCont_item"><text>备注：</text>{{classCont.remark ? classCont.remark : '无备注'}}</view>
				</view>
				<view class="popConfirm" v-if="tableType == 1">
					<view class="popCancle" @tap.stop="closeALL">取消</view>
					<view class="popYes" @tap.stop="gotoClass">前往课堂</view>
				</view>
				<view class="popConfirm popBtn" v-if="tableType == 2">
					<view class="popYes" @tap.stop="closeALL">确定</view>
				</view>
			</view>
		</view>
		<!-- 创建课程 -->
		<view class="pop" v-if="isCreate">
			<view class="popShort">
				<view class="popTitle">设置课程</view>
				<view class="popCont">
					<view class="popCont_item"><text>课程名称：</text><input type="text" placeholder="请输入课程名称" v-model="courseName" /></view>
					<view class="popCont_item"><text>备注：</text><textarea placeholder="请输入课程备注" v-model="courseRemark" /></view>
				</view>
				<view class="popConfirm">
					<view class="popCancle" @tap.stop="closeALL">取消</view>
					<view class="popDel" @tap.stop="del()" v-if="classCont.subject_name">删除</view>
					<view class="popYes" @tap.stop="create" v-else>添加</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import util from '@/common/util.js';
	export default {
		data() {
			return {
				time: Date.parse(new Date()) / 1000, //当前时间
				stuId: uni.getStorageSync('currentChild').student_id,
				parentid: uni.getStorageSync('parentid'), //当前班级所在机构Id
				groupid: uni.getStorageSync('groupid'), //当前班级Id
				groupName: uni.getStorageSync('groupname'), //当前班级名称
				navList: [{ //顶部选项卡列表
					name: '学期名称',
					type: 'Year',
					index: 0
				}, {
					name: '周名称',
					type: 'Week',
					index: 0
				}],
				type: '', //顶部选项卡选中名称
				isShowPop: false, //弹框是否显示
				showArr: [], //弹框内容列表
				classList: [], //班级列表
				yearList: [], //学期列表
				weekList: [], //周列表
				days: [{ //一周日期框架
					name: '周一'
				}, {
					name: '周二'
				}, {
					name: '周三'
				}, {
					name: '周四'
				}, {
					name: '周五'
				}, {
					name: '周六'
				}, {
					name: '周日'
				}],
				daysNew: [], //当前所选中周的一周日期列表
				courseList: [], //课程列表
				timeList: [], //时间段列表
				datas: [],
				isClass: false,
				classCont: {},
				setList: [], //时间套列表
				isCreate: false, //是否开启创建课程弹框
				courseName: '', //新建课程名称
				courseRemark: '', //新建课程名称
				signList: [], //签到列表
				isSelf: false, //是否改变了classType的值
			}
		},
		props: {
			classType: { //是否要添加班级判断 1不添加 2添加
				type: Number,
				default: 1
			},
			tableType: { //课表模式 1班级课表 2个人课表 3日程课表
				type: Number,
				default: 1
			},
			time_main_id: { //时间套ID tableType == 3(日程课表)时用到
				type: String,
				default: ''
			},
			schedule_id: { //日程ID tableType == 3(日程课表)时用到
				type: String,
				default: ''
			},
			selfType: { //课表模式 1班级课表-学校 2班级课表-私塾
				type: Number,
				default: 1
			},
			isParent: { //是否是家长创建私塾 1不是 2是
				type: Number,
				default: 1
			},
			schoolId: { //私塾ID isParent==2(家长创建私塾)时用到
				type: Number
			}
		},
		created() {
			if(this.classType == 2) {
				this.getClass();
			} else {
				if(this.tableType == 2) {
					this.navList[0].name = '年度名称';
				}
				if(this.tableType == 3) {
					this.getCourse();
				} else {
					this.getYear();
				}
			}
		},
		methods: {
			/* 初始化数据 */
			data() {
				this.time = Date.parse(new Date()) / 1000; //当前时间
				this.stuId = uni.getStorageSync('currentChild').student_id;
				this.parentid = uni.getStorageSync('parentid'); //当前班级所在机构Id
				this.groupid = uni.getStorageSync('groupid'); //当前班级Id
				this.groupName = uni.getStorageSync('groupname'); //当前班级名称
				this.yearList = [];
				this.weekList = [];
				this.timeList = [];
				this.courseList = [];
				this.datas = [];
				this.navList = [{
					name: '学期名称',
					type: 'Year',
					index: 0
				}, {
					name: '周名称',
					type: 'Week',
					index: 0
				}];
				if(this.tableType == 2) {
					this.navList[0].name = '年度名称';
				}
			},
			/* 获取班级列表 */
			getClass() {
				this.data();
				if(this.classType == 2 && this.navList[0].type != 'Classes') {
					this.navList.unshift({
						name: '班级名称',
						type: 'Classes',
						index: 0
					})
				}
				var obj = {
					student_id: this.stuId
				};
				if(this.selfType == 2) {
					obj.group_type = 2;
				}
				if(this.isParent == 2) {
					obj.group_type = 2
					obj.classroom_id =  this.schoolId
				}
				this.$zapi.apiPost('user/Grade.User/GradeList', obj).then(res => {
					if (res.data.code == 200 && res.data.data.length > 0) {
						var list = res.data.data;
						var cont = res.data.data[0];
						var index = 0;
						var groupid = uni.getStorageSync('groupid');
						list.forEach((item,key)=>{
							if(item.groupid == groupid) {
								index = key;
								cont = item;
							}
						})
						for (var i = 0; i < list.length; i++) {
							list[i]['isShow'] = false;
						}
						this.classList = list;
						this.classList[index].isShow = true;
						var num = this.judge('Classes'); //判断班级在nav列表中的索引
						this.navList[num].index = index; //nav列表班级索引
						this.navList[num].name = this.classList[index].group_name; //nav列表班级名称
						uni.setStorageSync('class_index',index);//班级索引
						uni.setStorageSync('groupid', cont.groupid);
						uni.setStorageSync('groupname', cont.group_name);
						uni.setStorageSync('parentid', cont.parent_id);
						this.parentid = uni.getStorageSync('parentid'); //当前班级所在机构Id
						this.groupid = uni.getStorageSync('groupid'); //当前班级Id
						this.groupName = uni.getStorageSync('groupname'); //当前班级名称
						if (this.parentid) {
							this.getYear(); //获取学期
						}
					} else {
						this.classList = [];
						this.showToast('您还未加入任何班级');
					}
				});
			},
			/* 获取学期列表 */
			getYear() {
				if(this.classType == 1 && this.tableType != 3) {
					this.data();
				}
				var _this = this;
				var data = {
					school_id: this.parentid,
					class_id: this.groupid
				}
				var url = 'mobile/schedule/semester/infos';
				if(this.tableType == 2) {
					url = 'person/semester/infos';
					data = {};
					data.usr_id = this.stuId;
					data.limit = 999;
				}
				this.$kbapi.apiPost(url, data).then(res => {
					var list = res.data.data;
					if(this.tableType == 2) {
						list = res.data.data.list;
					}
					if (res.data.code == 200 && list.length > 0) {
						var index = this.judge('Year'); //判断学期在nav列表中的索引
						var yearindex = 0; //学期下拉框选中索引
						for (var i = 0; i < list.length; i++) {
							list[i]['isShow'] = false;
							var startTime = list[i].semester_start + ' 00:00:00';
							var sum1 = new Date(startTime.replace(/\-/g, '/')).getTime() / 1000; //学期开始时间
							var endTime = list[i].semester_end + ' 23:59:59';
							var sum2 = new Date(endTime.replace(/\-/g, '/')).getTime() / 1000; //学期结束时间
							if (_this.time >= sum1 && _this.time <= sum2) {
								yearindex = i;
							}
						}
						_this.yearList = list;
						_this.yearList[yearindex].isShow = true;
						_this.navList[index].index = yearindex; //nav列表学期索引
						_this.navList[index].name = _this.yearList[yearindex].semester_name; //nav列表学期名称
						setTimeout(function() {
							_this.getWeek();
						}, 200);
					} else {
						_this.yearList = [];
						var title = '该班级还未添加学期列表或当前周没有课程';
						if(_this.tableType == 2) {
							title = '当前还未添加年度列表';
						}
						_this.showToast(title,'none',2500);
					}
				})
			},
			/* 获取周列表 */
			getWeek() {
				var _this = this;
				var index = this.judge('Year'); //判断学期在nav列表中的索引
				var data = {
					semester_id: this.yearList[this.navList[index].index].unid
				}
				var url = 'mobile/semester/week/infos';
				if(this.tableType == 2) {
					url = 'person/semester/week/infos';
				}
				this.$kbapi.apiPost(url, data).then(res => {
					if (res.data.code == 200 && res.data.data.length > 0) {
						var list = res.data.data;
						var index = this.judge('Week'); //判断周在nav列表中的索引
						var weekindex = 0; //周下拉框选中索引
						for (var i = 0; i < list.length; i++) {
							list[i]['isShow'] = false;
							var startTime = list[i].week_start + ' 00:00:00';
							var sum1 = new Date(startTime.replace(/\-/g, '/')).getTime() / 1000; //周开始时间
							var endTime = list[i].week_end + ' 23:59:59';
							var sum2 = new Date(endTime.replace(/\-/g, '/')).getTime() / 1000; //周结束时间
							if (_this.time >= sum1 && _this.time <= sum2) {
								weekindex = i;
							}
						}
						_this.weekList = list;
						_this.weekList[weekindex].isShow = true;
						_this.navList[index].index = weekindex; //nav列表周索引
						_this.navList[index].name = _this.weekList[weekindex].week_name; //nav列表周名称
						setTimeout(function() {
							_this.getCourse();
						}, 200);
					} else {
						_this.weekList = [];
						_this.showToast('该班级还未添加周期列表');
					}
				})
			},
			/* 获取签到列表 */
			getSign() {
				var index = this.judge('Week'); //判断周在nav列表中的索引
				var data = {
					semester_week_id: this.weekList[this.navList[index].index].unid,
					usr_id: this.stuId,
					class_id: this.groupid
				}
				this.$kbapi.apiPost('mobile/sign/course/week/infos', data).then(res => {
					if (res.data.code == 200 && res.data.data.length > 0) {
						this.signList = res.data.data;
						this.courseList.forEach((item,index)=>{
							this.signList.forEach((val,key)=>{
								if(item.day == val.day && item.time_lesson_id == val.time_lesson_id) {
									item.sign_type = val.sign_type;
								}
							})
						})
					} else {
						this.signList = [];
					}
				})
			},
			/* 获取课程列表 */
			getCourse() {
				var _this = this;
				var index = this.judge('Week'); //判断周在nav列表中的索引
				var url = ''
				var data = {}
				if(this.tableType == 1) {
					url = 'mobile/schedule/week/infos';
					data.semester_week_id = this.weekList[this.navList[index].index].unid;
					data.class_id = this.groupid;
				} else if (this.tableType == 2) {
					url = 'person/schedule/week/infos';
					data.semester_week_id = this.weekList[this.navList[index].index].unid;
					data.usr_id = this.stuId
				} else if(this.tableType == 3) {
					url = 'person/schedule/course/infos';
					data.schedule_id = this.schedule_id;
				}
				this.$kbapi.apiPost(url, data).then(res => {
					if (res.data.code == 200 && res.data.data.length > 0) {
						var list = res.data.data;
						list.forEach((item,index)=>{
							item['sign_type'] = 999;
						})
						_this.courseList = list;
						if(_this.tableType == 2) {
							uni.setStorageSync('myCourseId',list[0].unid);
							_this.$emit("getData",true);
						}
						setTimeout(function() {
							if(_this.tableType != 3) {
								_this.getStage();
								_this.getSign();
							}
						}, 200);
					} else {
						_this.courseList = [];
						if(_this.tableType == 2) {
							_this.$emit("getData",false);
						}
					}
					if(_this.tableType == 3) {
						_this.getStage();
					}
				})
			},
			/* 获取时段列表 */
			getStage() {
				var _this = this;
				var url = 'mobile/time/lesson/infos';
				var data = {}
				if(this.tableType != 1) {
					url = 'person/time/lesson/infos';
					var index = this.judge('Time'); //判断时间段在nav列表中的索引
					if(this.tableType == 3) {
						data.time_main_id = this.time_main_id
					} else {
						data.time_main_id = this.courseList[0].time_main_id
					}
				} else {
					data.time_main_id = this.courseList[0].time_main_id
				}
				this.$kbapi.apiPost(url, data).then(res => {
					var list = res.data.data;
					if(this.tableType != 1) {
						list = res.data.data.list;
					}
					if (res.data.code == 200 && list.length > 0) {
						for(var i = 0; i < list.length; i++) {
							list[i].start = list[i].lesson_start.substring(0, 5)
							list[i].end = list[i].lesson_end.substring(0, 5)
						}
						_this.timeList = list;
						if(this.tableType != 3) {
							_this.getDays();
						}
						_this.setData();
					} else {
						_this.timeList = [];
					}
				})
			},
			/* 数据处理 */
			setData:function(){
				this.datas = [];
				this.timeList.forEach((val,k)=>{
					this.datas[val.unid] = {}
					if(this.tableType != 3) {
						this.daysNew.forEach((item,key)=>{
							this.datas[val.unid][key+1] = {time:{}}
							this.datas[val.unid][key+1]['time'].timeStart = val.lesson_start
							this.datas[val.unid][key+1]['time'].timeEnd = val.lesson_end
						})
					} else {
						this.days.forEach((item,key)=>{
							this.datas[val.unid][key+1] = {time:{}}
							this.datas[val.unid][key+1]['time'].timeStart = val.lesson_start
							this.datas[val.unid][key+1]['time'].timeEnd = val.lesson_end
						})
					}
				});
				this.courseList.forEach((item,key)=>{
					var time = this.datas[item.time_lesson_id][item.day].time;
					this.datas[item.time_lesson_id][item.day] = item;
					this.datas[item.time_lesson_id][item.day].time = time;
					var startTime = this.datas[item.time_lesson_id][item.day].dateTime +' ' + this.datas[item.time_lesson_id][item.day]['time'].timeStart;
					this.datas[item.time_lesson_id][item.day].startTime = new Date(startTime).getTime() / 1000; //本节课开始时间
					var endTime = this.datas[item.time_lesson_id][item.day].dateTime +' ' + this.datas[item.time_lesson_id][item.day]['time'].timeEnd;
					this.datas[item.time_lesson_id][item.day].endTime = new Date(endTime).getTime() / 1000; //本节课结束时间
					if(this.datas[item.time_lesson_id][item.day].startTime > this.time) { 
						this.datas[item.time_lesson_id][item.day].timeType = 1; //未开始
					} else if(this.datas[item.time_lesson_id][item.day].endTime < this.time) {
						this.datas[item.time_lesson_id][item.day].timeType = 2; //已结束
					} else if(this.datas[item.time_lesson_id][item.day].startTime <= this.time && this.time <= this.datas[item.time_lesson_id][item.day].endTime) {
						this.datas[item.time_lesson_id][item.day].timeType = 3; //进行中
					}
				})
			},
			/* 获取周列表日期 */
			getDays() {
				var _this = this;
				var index = this.judge('Week'); //判断周在nav列表中的索引
				var currentDate = new Date(this.weekList[this.navList[index].index].week_start.replace(/\-/g, '/'))
				var timesStamp = currentDate.getTime();
				var currenDay = currentDate.getDay();
				var dates = [];
				for (var i = 0; i < 7; i++) {
					dates.push(util.getLeftTime(timesStamp + 24 * 60 * 60 * 1000 * (i - ((currenDay + 6) % 7))));
				}
				_this.daysNew = _this.days; // 每次清空上一次的时间，避免累加
				for (var i = 0; i < _this.daysNew.length; i++) {
					_this.daysNew[i]['dateTime'] = dates[i].replace(/\-/g, '/');
					_this.daysNew[i]['time'] = dates[i].substr(5).replace(/\-/g, '.');
					
				}
				for(var i = 0; i < _this.daysNew.length; i++) {
					for(var j = 0; j < _this.courseList.length; j++) {
						if(_this.courseList[j].day === (i+1)) {
							_this.courseList[j].dateTime = _this.daysNew[i].dateTime
						}
					}
				}
				_this.$forceUpdate();
			},
			/* 顶部选项卡切换赋值 */
			navClick(type) {
				this.isShowPop = !this.isShowPop;
				this.type = type;
				this.showArr = [];
				switch (type){
					case 'Classes':
						this.classList.forEach(item => {
							let obj = {
								name: item.group_name,
								isShow: item.isShow
							}
							this.showArr.push(obj)
						})
						break;
					case 'Year':
						this.yearList.forEach(item => {
							let obj = {
								name: item.semester_name,
								isShow: item.isShow
							}
							this.showArr.push(obj)
						})
						break;
					case 'Week':
						this.weekList.forEach(item => {
							let obj = {
								name: item.week_name,
								isShow: item.isShow
							}
							this.showArr.push(obj)
						})
						break;
					default:
						break;
				}
			},
			/* 弹框内容切换 */
			itemClick(index,name) {
				this.courseList = [];
				this.timeList = [];
				this.daysNew = [];
				this.datas = [];
				var num = this.judge(this.type); //判断周在nav列表中的索引
				var state = {
					name: '学期名称',
					type: 'Year',
					index: 0
				}
				var state1 = {
					name: '周名称',
					type: 'Week',
					index: 0
				}
				var length = this.navList.length;
				switch (this.type){
					case 'Classes':
						this.navList[1] = state;
						this.navList[2] = state1;
						break;
					case 'Year':
						this.navList[length-1] = state1;
						break;
					default:
						break;
				}
				this.navList[num].index = index;
				this.navList[num].name = name;
				this.isShowPop = false;
				switch (this.type){
					case 'Classes':
						this.parentid = this.classList[this.navList[num].index].parent_id;
						this.groupid = this.classList[this.navList[num].index].groupid;
						this.groupName = this.classList[this.navList[num].index].group_name;
						uni.setStorageSync('groupid', this.groupid);
						uni.setStorageSync('groupname', this.groupName);
						uni.setStorageSync('parentid', this.parentid);
						uni.setStorageSync('class_index', index);
						this.yearList = [];
						this.weekList = [];
						this.classList.forEach(item => {
							item.isShow = false;
						})
						this.classList[this.navList[num].index].isShow = true;
						this.getYear();
						break;
					case 'Year':
						this.weekList = [];
						this.yearList.forEach(item => {
							item.isShow = false;
						})
						this.yearList[this.navList[num].index].isShow = true;
						this.getWeek();
						break;
					case 'Week':
						this.weekList.forEach(item => {
							item.isShow = false;
						})
						this.weekList[this.navList[num].index].isShow = true;
						this.getCourse();
						break;
					default:
						break;
				}
			},
			/* 判断nav数组索引 */
			judge(type) {
				var index = 0;
				for(var i = 0; i < this.navList.length; i++) {
					if(type == this.navList[i].type) {
						index = i;
					}
				}
				return index;
			},
			/* 关闭弹框 */
			closeALL() {
				this.isShowPop = false;
				this.isClass = false;
				this.isCreate = false;
			},
			/* 查看课程详情 */
			showClass(item,index,unid) {
				this.classCont = {};
				this.courseName = '';
				this.courseRemark = '';
				if(this.tableType == 1 && item.subject_name) {
					this.isClass = !this.isClass;
					item.time.timeStart = item.time.timeStart.substring(0, 5);
					item.time.timeEnd = item.time.timeEnd.substring(0, 5);
					item.school_id = this.parentid;
					var weekIndex = this.judge('Week'); //判断周在nav列表中的索引
					item.semester_week_id = this.weekList[this.navList[weekIndex].index].unid;
					item.className = this.groupName;
					this.classCont = item;
				} else if (this.tableType == 2) {
					this.isClass = !this.isClass;
					item.time.timeStart = item.time.timeStart.substring(0, 5);
					item.time.timeEnd = item.time.timeEnd.substring(0, 5);
					this.classCont = item;
				} else if (this.tableType == 3) {
					this.isCreate = !this.isCreate;
					if(item.subject_name) {
						this.courseName = item.subject_name;
						this.courseRemark = item.remark;
						this.classCont = item;
					} else {
						item.day = index;
						item.time_lesson_id = unid;
						this.classCont = item;
					}
				}
			},
			/* 创建课程 */
			create() {
				var data = {
					schedule_id: this.schedule_id,
					subject_name: this.courseName,
					day: this.classCont.day,
					time_lesson_id: this.classCont.time_lesson_id,
				}
				if(this.courseRemark) {
					data.remark = this.courseRemark
				}
				if(this.courseName == '') {
					this.showToast('请输入课程名称');
				} else {
					this.$kbapi.apiPost('person/schedule/course/save',data).then(res=>{
						if(res.data.code == 200) {
							var result = res.data.data;
							this.datas[result.time_lesson_id][result.day] = result;
						} else {
							this.showToast(res.data.message);
						}
						this.isCreate = false;
					})
				}
			},
			/* 删除课程 */
			del() {
				var _this = this;
				this.isCreate = false;
				uni.showModal({
					title: '删除提示',
					content: '确定要删除吗？',
					confirmColor: '#FF9900',
					success:function(res){
						if(res.confirm) {
							_this.$kbapi.apiPost('person/schedule/course/delete/'+_this.classCont.unid,{unid:_this.classCont.unid}).then(res=>{
								if(res.data.code == 200) {
									var time = _this.classCont.time;
									_this.datas[_this.classCont.time_lesson_id][_this.classCont.day] = {time:time}
									_this.$forceUpdate();
								} else {
									_this.showToast(res.data.message);
								}
							})
						}
					}
				})
			},
			/* 前往课堂 */
			gotoClass() {
				this.isClass = false;
				uni.setStorageSync('courseCont',this.classCont);
				uni.navigateTo({
					url: '/pages/classRoom/coursedetails',
				})
			},
			/* 提示方法 */
			showToast(title,icon,time) {
				var icons = 'none';
				var duration = 1500;
				if(icon) {
					icons = icon;
				}
				if(time) {
					duration = time;
				}
				uni.showToast({
					title: title,
					icon: icons,
					mask: true,
					duration: duration
				})
			}
		},
		watch: {
			classType(newVal) {
				this.isSelf = true;
				this.classType = newVal;
				if(this.classType == 2) {
					this.getClass();
					var _this = this;
					if(this.isSelf) {
						setTimeout(function() {
							_this.isSelf = false;
						}, 100);
					}
				} else {
					if(this.tableType == 2) {
						this.navList[0].name = '年度名称';
					}
					if (this.tableType == 3) {
						this.data();
						this.getCourse();
					} else {
						this.getYear();
					}
				}
			},
			selfType(newVal) {
				this.selfType = newVal;
				var _this = this;
				if(!this.isSelf) {
					setTimeout(function() {
						_this.getClass();
					}, 10);
				}
			}
		}
	}
</script>

<style lang="scss">
	/* 顶部选项卡 */
	.nav{
		width: 100%;
		height: 80upx;
		display: flex;
		justify-content: space-around;
		align-items: center;
		.navItem{
			display: flex;
			justify-content: center;
			align-items: center;
			color: #333333;
			font-size: 34upx;
			& i {
				margin-left: 20upx;
			}
		}
	}
	/* 空数据 */
	.none{
		width: 100%;
		display: flex;
		flex-wrap: wrap;
		justify-content: center;
		& i{
			color: #E5E5E5;
			font-size: 500upx;
			line-height: 1;
		}
		& text {
			color: #C2C2C2;
			font-size: 42upx;
		}
	}
	/* 新建课程按钮 */
	.create{
		width: 360upx;
		border-radius: 8upx;
		background: rgba(0, 213, 162, 1);
		color: #FFFFFF;
		font-size: 34upx;
		text-align: center;
		line-height: 80upx;
		margin: 54upx auto 0;
	}
	/* 课程列表 */
	.table{
		display: table;
		width: calc(100% - 2upx);
		height: 100%;
		background: #FFFFFF;
		border-collapse: collapse;
		.table-tr{
			display: table-row;
			.table-td{
				display: table-cell;
				text-align: center;
				vertical-align: middle;
				border: 2upx solid #E5E5E5;
				.date {
					color: #333333;
					font-size: 24upx;
					text-align: right;
					margin-right: 8upx;
				}
				.time {
					color: #333333;
					font-size: 24upx;
					text-align: left;
					margin-left: 8upx;
				}
				.day-name{
					color: #333333;
				}
				.day-time{
					color: #666666;
					font-size: 24upx;
				}
				.sign{
					width: 12upx;
					height: 12upx;
					border-radius: 50%;
					text-align: center;
					margin-left: calc(50% - 6upx);
					margin-top: 4upx;
				}
				.signSuccess{
					background-color: #00D5A2;
				}
				.signLate{
					background-color: #FF9900;
				}
				.signDefault{
					background-color: #FF7171;
				}
				.signIngLate{
					background-color: #FFFFFF;
				}
			}
			.course-time{
				padding: 16upx 0;
				& view {
					line-height: 1;
				}
			}
			.course-text{
				width: 12.2%;
				padding: 10upx 0;
			}
			.time-less{
				color: #000000;
			}
			.time-ing {
				color:#FFFFFF;
				background:#FF9900; 
			}
			.time-more {
				color:#FF9900;
			}
		}
	}
	/* 弹框选择 */
	.pop {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background: rgba(0, 0, 0, 0.6);
		z-index: 9;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	
	.popView {
		width: 80%;
		height: 700upx;
		border-radius: 40upx;
		overflow: hidden;
		background: #FFFFFF;
	}
	
	.popShort {
		width: 80%;
		overflow: hidden;
		border-radius: 40upx;
		background: #FFFFFF;
		.popTitle{
			color: #333333;
			font-size: 38upx;
			height: 100upx;
			line-height: 100upx;
			text-align: center;
		}
		.popCont{
			min-height: 140upx;
			padding: 30upx 50upx 14upx;
			border: 2upx;
			border-style: solid none;
			border-color: #E5E5E5;
			.popCont_item{
				color: #333333;
				font-size: 32upx;
				display: flex;
				align-items: center;
				justify-content: flex-start;
				margin: 20upx auto;
				& text{
					color: #999999;
					white-space: nowrap;
				}
				& input,
				& textarea{
					padding: 20upx;
					margin: 30upx auto;
					border: 2upx solid #E5E5E5;
				}
			}
		}
		.popConfirm{
			height: 90upx;
			display: flex;
			& view {
				color: #FF9900;
				font-size: 34upx;
				width: 50%;
				text-align: center;
				line-height: 90upx;
			}
			.popCancle{
				color: #999999;
				border-right: 2upx solid #E5E5E5;
			}
			.popDel{
				color: #FF7171;
			}
		}
		.popBtn{
			justify-content: space-around;
			align-items: center;
		}
	}
	
	.popItem {
		height: 88upx;
		line-height: 88upx;
		text-align: center;
		color: #666666;
		font-size: 36upx;
		border-top: 2upx solid #E5E5E5;
	}
	
	.popItem:first-child {
		border-top: none;
	}
	
	.popActive {
		color: #FF9900;
	}
</style>
